package sz.szsmk.citizencard.mvp.presenter;

import android.widget.Toast;

import javax.inject.Inject;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.AccessTokenRequest;
import sz.szsmk.citizencard.model.network.bean.response.QueryDonationRes;
import sz.szsmk.citizencard.mvp.contract.IDonationContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/5 13:33
 * description:
 */
public class DonationPresenter extends IBasePresenter
        implements IDonationContact.IDonationPresenter<IDonationContact.IDonationView> {


    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public DonationPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }


    @Override
    public void getDonation() {
        AccessTokenRequest accessTokenRequest = new AccessTokenRequest();
        mNetworkDateSource.quryCommonwealInfor(accessTokenRequest, new SubscribeResult<QueryDonationRes>() {
            @Override
            protected void onOk(QueryDonationRes response) {
                ((IDonationContact.IDonationView) mView).getDonationSucc(response);

            }

            @Override
            protected void onFailure(QueryDonationRes response) {
                super.onFailure(response);
                ((IDonationContact.IDonationView) mView).getDonationFail();
                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }
}
